package com.itheima.controller.backend.admin;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.common.entity.Result;
import com.itheima.pojo.Order;
import com.itheima.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 预约管理
 *
 * @author syy
 * @version 1.0
 * @ClassName OrderController
 * @create 2024-11-01-9:26
 */
@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 分页查询预约信息
     *
     * @param pageBean
     * @return
     */
    @PostMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean pageBean) {
        return orderService.findPage(pageBean);
    }

    @PostMapping("/update")
    public Result update(@RequestBody Order order) {
        try {
            orderService.updateOrder(order);
            return new Result(true, MessageConstant.ORDER_SUCCESS);
        } catch (Exception e) {
            log.error("编辑预约信息失败:{}", e.getMessage());
            return new Result(false, MessageConstant.ORDER_FULL);

        }

    }
}